<?php
define('DEFAULT_TABLE_ROWS', 1);
?>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js;"></script>

<?php
include "functions".DIRECTORY_SEPARATOR."committee.php";
include "functions".DIRECTORY_SEPARATOR."utils.php";
include "forms_definitions".DIRECTORY_SEPARATOR."retire_program.php";

?>
<script>

$(document).ready(function(){
	 $("#saveButton").click(function(){
		
	 });
});

</script>
<?php
	
//get the program with CUI_CF = $var_cui_furnizor	
$program = mysqli_fetch_assoc(getProgram($var_cui_furnizor, $id_furnizori_programe, $dbc));

//set the form and the current values 
$retire_program_form = setRetireProgramForm($program);

//verify the initial/current values 
$retire_program_form = verificationStep($retire_program_form);

//generate the content fron defined form table
$form_content = generate_form_content($retire_program_form);

$erori = "";




$get_form=<<<GATA
	<form method="post" id="FORM_ID" action ="user_commission_search.php"  >  
		<table border="0" width="100%" cellspacing="3" cellpadding="3" align="center">
			$form_content
			<input type="hidden" name="save_retire_program" value="true">
			<input type="hidden" name="cui_furnizor" value="$var_cui_furnizor"> 
			<input type="hidden" name="id_furnizori_programe" value=" $id_furnizori_programe">
			<tr>
				<td></td><td><input type ="submit" value = "Retrage"</td>
			</tr>
		</table>
	</form>
GATA;
	
//display the form
if($_SERVER['REQUEST_METHOD'] == 'GET')
{
        echo $get_form;
 }
 else if($_SERVER['REQUEST_METHOD'] == 'POST')
{
	if (formConstraintsSatisfied($retire_program_form, $erori))
	{
		saveProgramRetirement($_POST["nr_retragere_autorizatie"],
							  $_POST["data_retragere_autorizatie"],
							  $_POST["motiv_retragere_autorizatie"], $_POST['cui_furnizor'], $_POST['id_furnizori_programe'], $dbc);
		header("Location:user_commission_search.php?cui_furnizor=".$_POST['cui_furnizor']."");
		//TO DO: echo "Programul a fost retras cu succes!";
		exit;
	}
	else {
		//rebuild the form
		$form_content = generate_form_content($retire_program_form);
$form_post=<<<GATA
	<form method="post" action = "user_commission_search.php">
		<table border="0" width="100%" cellspacing="3" cellpadding="3" align="center">
		$form_content
		<input type="hidden" name="save_retire_program" value="true">
		<input type="hidden" name="cui_furnizor" value="$var_cui_furnizor"> 
		<input type="hidden" name="id_furnizori_programe" value=" $id_furnizori_programe">
		<tr>
			<td><input type ="submit" value = "Salveaza" 
			onclick="this.form.target='_self';return true;" >
			</td>
		</tr>
</table>
</form>
GATA;

			echo $form_post;
			echo "<font color=\"red\">".$erori."</font>";
		
		}
  

}

?>